home *** CD-ROM | disk | FTP | other *** search
- /*
-
- #include <values.h>
- #include <types.h>
- #include <quickdraw.h>
- #include <fonts.h>
- #include <events.h>
- #include <controls.h>
- #include <windows.h>
- #include <menus.h>
- #include <textedit.h>
- #include <dialogs.h>
- #include <desk.h>
- #include <scrap.h>
- #include <toolutils.h>
- #include <memory.h>
- #include <segload.h>
- #include <files.h>
- #include <osutils.h>
- #include <osevents.h>
- #include <diskinit.h>
- #include <packages.h>
- #include <traps.h>
-
-
- #include <ctype.h>
- #include <fcntl.h>
- #include <string.h>
- #include <stdio.h>
- #include <ErrMgr.h>
- #include <CursorCtl.h>
- #include <Errors.h>
-
- #include <Devices.h>
-
- */
-
-
- #define NIL_POINTER 0L
- #define MOVE_TO_FRONT -1L
- #define REMOVE_ALL_EVENTS 0
- #define VISIBLE 0
-
-
- #define PLAIN 0
- #define PLAIN_ITEM 1
- #define BOLD_ITEM 2
- #define ITALIC_ITEM 3
- #define UNDERLINE_ITEM 4
- #define OUTLINE_ITEM 5
- #define SHADOW_ITEM 6
-
- #define FALSE (0)
- #define TRUE (!FALSE)
-
- #define INCLUDE_SECONDS TRUE
-
- #define ADD_CHECK_MARK TRUE
- #define REMOVE_CHECK_MARK FALSE
-
- #define DRAG_THRESHOLD 30
-
- #define MIN_SLEEP 0L
- #define NIL_MOUSE_REGION 0L
-
- #define WNE_TRAP_NUM 0x60
- #define UNIMPL_TRAP_NUM 0x9F
-
- #define QUIT_ITEM 1
- #define ABOUT_ITEM 1
-
- #define NOT_A_NORMAL_MENU -1
-
- #define ABOUT_ALERT 400
-
- #define HIER_MENU_CHAR '\x1b'
-
- typedef struct MenuItemRecord{char menuItemString[90]; /*Trouble if string is over 90*/
- int menuItemCommand;
- int menuItemMark;
- int menuItemStyle;
- }MenuItem;
-
-
- long allMenuChoice(void);
- void figureMenuRectSize(MenuHandle aMenuH, MenuHandle aHMenuH, Rect *menuRect);
- void DrawMenuWindow(int menuItemCount,MenuItem **pickListH,int *lineHeightPtr);
- pascal long main( Point thePoint );
- void HandleJKMouseDown( Point clickPoint, long *resultPtr, int hMenuID,
- int lineHeight,WindowPtr menuWindow);
- char specialMenu(MenuHandle theMenuH);
-
- /*********************** Main *********/
-
- /*************** MenuSelect( gTheEvent.where ) ************/
-
- pascal long main( Point thePoint )
- {
- long oldMenuSelectResult, deadMenuChoice, temp;
- char theChar;
- Boolean done;
- EventRecord jkMenuEvent;
- int theMenu, theItem, lineHeight;
- MenuHandle theMenuH, theHMenuH;
- long int ignoreThis;
- short deadCmdMark, deadCmdChar, menuItemCount, i;
- MenuItem **pickListH;
- Rect menuRect;
- WindowPtr menuWindow;
-
- void (*menuHandleProc) ();
-
- long *start;
-
- asm
- {
- move.l a0, start
- }
-
- oldMenuSelectResult = CallPascalL(thePoint,start[3]);
-
- if (!oldMenuSelectResult)
- {
- deadMenuChoice = allMenuChoice();
- theMenu = HiWord( deadMenuChoice );
- if (theItem = LoWord( deadMenuChoice ))
- {
- theMenuH = GetMHandle(theMenu);
- GetItemMark (theMenuH, theItem, &deadCmdMark);
- GetItemCmd (theMenuH, theItem, &deadCmdChar);
- theHMenuH = GetMHandle(deadCmdMark);
- if ((deadCmdChar == '\x1b'))/*&&
- (!specialMenu(theHMenuH = GetMHandle(deadCmdMark))))
- */ {
- HLock(theHMenuH);
- figureMenuRectSize(theMenuH,theHMenuH,&menuRect);
- /* menuItemCount = CountMItems(theHMenuH);
- pickListH = (MenuItem **)NewHandle(
- sizeof(struct MenuItemRecord)*menuItemCount );
- */
- menuWindow = NewWindow( (void *)NIL_POINTER,
- (Rect *)&menuRect,
- (ConstStr255Param)"\pTest",
- (Boolean)!VISIBLE,
- (short)altDBoxProc,
- (WindowPtr)MOVE_TO_FRONT,
- (Boolean)FALSE,
- (long)'\xF0');
- SetPort( menuWindow );
-
- menuHandleProc = (void (*) ())(*((*theHMenuH)->menuProc));
-
- i = 0;
-
- GlobalToLocal((Point *)&menuRect.bottom);
- menuRect.top = -20;
- menuRect.left = 0;
- CallPascal((short)mDrawMsg,theHMenuH,&menuRect,thePoint,&i,
- menuHandleProc);
-
- done = FALSE;
- while (!done)
- {
- if (GetNextEvent( everyEvent, /*mUpMask+keyDownMask,*/ &jkMenuEvent ))
- switch ( jkMenuEvent.what)
- {
- case mouseDown:
- i=0;
- GlobalToLocal(&jkMenuEvent.where);
- while (Button())
- {
- GetMouse(&thePoint);
- CallPascal((short)mChooseMsg,theHMenuH,&menuRect,
- thePoint,&i,menuHandleProc);
- }
- temp = (**theHMenuH).menuID;
- temp <<= 16;
- temp += i;
- if (i == 0)
- oldMenuSelectResult = 0;
- else
- oldMenuSelectResult = temp;
-
- /* HandleJKMouseDown(jkMenuEvent.where, &oldMenuSelectResult,
- (**theHMenuH).menuID,lineHeight,menuWindow);
- */
-
- done = !FALSE;
- break;
- case keyDown:
- case autoKey:
- theChar = jkMenuEvent.message & charCodeMask;
- if (theChar== 0x1B)
- done = !FALSE;
- break;
- case activateEvt:
- if ((jkMenuEvent.message == (long)menuWindow)&&
- (!(activeFlag&jkMenuEvent.modifiers)))
- {
- done = !FALSE;
- }
- break;
-
- }
- }
- DisposeWindow( menuWindow );
- /* DisposHandle( (Handle)pickListH );
- */
- HUnlock(theHMenuH);
- }
- }
- };
- return oldMenuSelectResult;
-
- }
- char specialMenu(MenuHandle theMenuH)
- {
- short menuIdNumber;
- Str255 menuStringTitle;
-
- menuIdNumber = 3333;
- menuStringTitle[0] = 0;
- return (*(**NewMenu(menuIdNumber,menuStringTitle)).menuProc)
- !=(*(**theMenuH).menuProc);
- }
-
- /*********************** HandleJKMouseDown *********/
-
- void HandleJKMouseDown( Point clickPoint, long *resultPtr, int hMenuID,
- int lineHeight, WindowPtr menuWindow)
- {
- WindowPtr whichWindow;
- short int thePart;
- long int menuSelChoice;
- int tempItem;
-
- Debugger();
- thePart = FindWindow( clickPoint, &whichWindow );
- if (whichWindow != menuWindow)
- *resultPtr = 0;
- else
- {
- SetPort(menuWindow);
- GlobalToLocal(&clickPoint);
- tempItem = clickPoint.v/lineHeight;
- *resultPtr = hMenuID;
- *resultPtr <<= 16;
- *resultPtr += ++tempItem;
- }
- }
- /*********************** figureMenuRectSize *********/
- void figureMenuRectSize(MenuHandle aMenuH, MenuHandle aHMenuH,Rect *menuRect)
- {
- short *tempPtr,i;
-
- menuRect->top = 0;
- /*get left edge of menu in menu bar*/
- menuRect->left = 0;
- tempPtr = (*(int **)MenuList);
- tempPtr+=3;
- for (i=1;i<=((int)**(int **)MenuList)/6;++i&&!menuRect->left,tempPtr+=3)
- {
- if (*(MenuHandle *)tempPtr == aMenuH)
- menuRect->left = tempPtr[2];
- };
- menuRect->right = menuRect->left + (*aHMenuH)->menuWidth+20;
- menuRect->bottom = menuRect->top + (*aHMenuH)->menuHeight+20;
-
- /* if (menuRect->right > screenBits.bounds.right)
- {
- menuRect->right = screenBits.bounds.right;
- menuRect->left = menuRect->right - (*aHMenuH)->menuWidth;
- };
- if (menuRect->bottom > screenBits.bounds.bottom)
- {
- menuRect->bottom = screenBits.bounds.bottom;
- };
- */
- }
-
- /************* DrawMenuWindow *************************/
-
- void DrawMenuWindow(int menuItemCount,MenuItem **pickListH,int *lineHeightPtr)
- {
- FontInfo fontStuff;
- int insetSpace, i;
-
-
- TextFont(0);
- TextSize(0);
- GetFontInfo(&fontStuff);
- insetSpace = fontStuff.widMax+1;
- MoveTo(1,fontStuff.ascent+1);
- *lineHeightPtr =fontStuff.ascent+fontStuff.descent+fontStuff.leading;
- for(i = 0 ;i<=menuItemCount;)
- {
- if ((((*pickListH)[i]).menuItemString)[1]=='-') /*SysBeep(30)*/;
- if ( ((*pickListH)[i]).menuItemMark )
- DrawChar(((*pickListH)[i]).menuItemMark);
- MoveTo(insetSpace,fontStuff.ascent+1+((i)*(*lineHeightPtr)));
- TextFace(((*pickListH)[i]).menuItemStyle);
- DrawString(&((*pickListH)[i]).menuItemString);
- TextFace(0);
- MoveTo(1,fontStuff.ascent+1+(++i*(*lineHeightPtr)));
- }
-
- }
-
- /*********************** allMenuChoice *********/
-
- long int allMenuChoice(void)
- /* This simulates MenuChoice, but works for all machines */
- {
- struct SysEnvRec theWorld;
- SysEnvirons(1,&theWorld);
- return (theWorld.machineType>0)&&(theWorld.machineType<4)?
- MenuDisable:
- MenuChoice();
- }
-
-